package wrapper;

public class WrapperConstructors {
	public static void main(String[] args) {
		Integer i1 = new Integer(42);
		Integer i2 = new Integer("42");
		
		Float f1 = new Float(3.14f);
		Float f2 = new Float("3.14f");
		
		Character c1 = new Character('c');
		
		Boolean b = new Boolean("false");
		if(b) {}
	
		Integer i3 = Integer.valueOf("101011", 2);
		Float f3 = Float.valueOf("3.14f");
	
		/* using wrapper conversion utilities */
		Integer i = new Integer(42);
		System.out.println("byte:" + i.byteValue() + " short:" + i.shortValue() + " double:" +
						   i.doubleValue());
		
		Float f = new Float(3.89f);
		System.out.println("short: " + f.shortValue());
		
		double d4 = Double.parseDouble("3.14f");
		System.out.println("d4 = " + d4);
		
		Integer ii = 10;
		Short ss = 10;
		Long ll = 10l;
		Double dd = 10.0;
		Float ff = 10.0f;
		Byte bb = 10;
		Character cc = 'c';
		Boolean bl = true;
		System.out.println(ii + " " + ss + " " + ll + " " +
						    dd + " " + ff + " " + bb + " " + cc + " " + bl);
		
		/* parseXxx() and valueOf() */
		double d5 = Double.parseDouble("3.14");
		System.out.println("d5 = " + d5);
		
		Double d6 = Double.valueOf("3.14");
		System.out.println(d6 instanceof Double);
		
		Long L2 = Long.parseLong("101010", 2);
		System.out.println("L2 = " + L2);
		
		Long L3 = Long.valueOf("101010", 2);
		System.out.println("L3 value = " + L3);
		
		/* toString() */
		Double d = new Double("3.14");
		System.out.println("d = " + d.toString());
		
		String s1 = Double.toString(3.14);
		System.out.println(s1);
		
		String s2 = "hex = " + Long.toString(254, 16);
		System.out.println(s2);
		
		String s3 = Integer.toHexString(254);
		System.out.println("254(hex) = " + s3);
		
		String s4 = Long.toOctalString(254);
		System.out.println("254(oct) = " + s4);
		
		Boolean bl1 = Boolean.valueOf("true");
		System.out.println(bl1);
		
		/* Autoboxing */
		Integer y = 567;
		Integer x = y;
		System.out.println(y==x);
		y++;  //what actually happened, is that a second wrapper object was created and its value was set to 568
		System.out.println(x + " " + y);
		System.out.println(y==x);
		
		//beyond the range -128 to 127
		Integer x1 = 1000;
		Integer y1 = 1000;
		if(x1 == y1) System.out.println("same object");
		if(x1.equals(y1)) System.out.println("meaningfully equal");
		
		//within the range -128 to 127
		Integer x2 = 10;
		Integer y2 = 10;
		if(x2 == y2) System.out.println("same object");
		if(x2.equals(y2)) System.out.println("meaningfully equal");
		
		
	}

}


